package com.wlyuan.index.domain.source.repository;

import com.wlyuan.core.domain.repository.BaseRepository;
import com.wlyuan.index.domain.source.Source;
import com.wlyuan.index.domain.source.valueobj.Modifiers;
import com.wlyuan.index.domain.source.valueobj.SourceId;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author yuanjie
 */
public interface SourceRepository extends BaseRepository<Source, SourceId> {
    Map<SourceId, Source> getSourceMap(Collection<SourceId> sourceIds);

    void unbound(SourceId sourceId);

    void bound(SourceId sourceId, List<SourceId> boundIds);

    default void bound(SourceId sourceId, SourceId boundId) {
        this.bound(sourceId, Collections.singletonList(boundId));
    }

    default void bound(List<SourceId> sourceIds, SourceId boundId) {
        if (CollectionUtils.isEmpty(sourceIds)) {
            return;
        }
        sourceIds.forEach(sourceId -> this.bound(sourceId, boundId));
    }

    Map<SourceId, List<Source>> getBoundsMap(Collection<SourceId> sourceIds);

    Map<SourceId, List<Source>> getBoundsMap(Collection<SourceId> sourceIds, Modifiers modifier);

    Collection<SourceId> listIds();
}
